﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace linkouqs.Gamekit {

    public class CharacterStateStand : CharacterState {

        CharacterAbilityAttack m_Attack;
        CharacterAbilityTake m_Take;
        CharacterAbilityJumpAttack m_JumpAttack;
        CharacterAbilityPush m_Push;

        public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
            base.OnStateEnter(animator, stateInfo, layerIndex);
            m_Attack = animator.GetComponent<CharacterAbilityAttack>();
            m_Take = animator.GetComponent<CharacterAbilityTake>();
            m_JumpAttack = animator.GetComponent<CharacterAbilityJumpAttack>();
            m_Push = animator.GetComponent<CharacterAbilityPush>();
            if (m_JumpAttack != null) {
                m_JumpAttack.ResetJumpAttackTimes();
            }
        }

        public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {

            if (Character.IsPressedJump()) {
                return;
            }

            if (!Character.IsPressedAction()) {
                return;
            }

            if (m_Push.CanStartAction()) {
                Character.LockDirection = true;
                m_Push.StartAction();
                return;
            }

            /// 是否可以抬起物体
            if (m_Take.CanStartAction()) {
                m_Take.StartAction();
                return;
            }

            /// 是否可以普通攻击
            if (m_Attack.CanStartAction()) {
                m_Attack.StartAction();
                return;
            }
        }

        public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
            m_Push = null;
            m_JumpAttack = null;
            m_Take = null;
            m_Attack = null;
            base.OnStateExit(animator, stateInfo, layerIndex);
        }

    }

}
